/**
 * 物流界面
 */
class logisticsSub extends eui.Component{
    private return:eui.Button;
    private address:eui.Button;

    private scroll:eui.Scroller;
    private list:eui.List;

    private _logisticsInfoUI:logisticsInfo;

    private _arrayData:eui.ArrayCollection;
    private _logisticsData:Array<any> = [];

    private _addressListUI:addressList;
    public constructor(){
        super();
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "logisticsSkin"; 
    }

    private createCompleteEvent():void{
        this.removeEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent, this);
        this.inIt();
    }

    private inIt(){
        this.return.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
            this.dispatchEventWith("return");
        },this);
        this.address.addEventListener(egret.TouchEvent.TOUCH_TAP,this.mbtnHandler,this);
        Dispatcher.ins.addEventListener("logisticsList", this.assignValue , this);
        this.getList();

        this._arrayData = new eui.ArrayCollection(this._logisticsData);
        this.list.dataProvider = this._arrayData;
        this.list.itemRenderer = logisticsIR;
        this.list.addEventListener(eui.ItemTapEvent.ITEM_TAP,(evt:egret.Event)=>{
            var dataList:eui.List = evt.target;
            var item = dataList.selectedItem;
            if(item.Status == 1){
                let toast = new Toast();
                toast.show("审核中，暂无物流信息");
                this.addChild(toast);
                return;
            }
            if(!this._logisticsInfoUI){
                this._logisticsInfoUI = new logisticsInfo();
                this._logisticsInfoUI.addEventListener("return",()=>{
                    this.removeChild(this._logisticsInfoUI);
                },this);
            }
            this._logisticsInfoUI.getInfo(item);
            this.addChild(this._logisticsInfoUI);
        },this);
    }
    private mbtnHandler(evt:egret.TouchEvent):void{
        let btn = evt.currentTarget;
        switch(btn){
            case this.address:{
                if(!this._addressListUI){
                    this._addressListUI = new addressList();
                }else{
                    this._addressListUI.getList();
                }
                this.addChild(this._addressListUI);
            }
        }
     }
     public getList():void{
         socket.request("logisticsList");
     }
     public assignValue(evt:GameEvent):void{
        let obj = evt.data;
        let arr = obj.list;
        this._logisticsData = [];
        for(let i = 0,lg = arr.length;i < lg;i ++){
            let trObj = arr[i];
            if(trObj.Status == 1){
                trObj.status = "审核中"
            }else if(trObj.Status == 2){
                trObj.status = "已发货"
            }else{
                trObj.status = "已送达"
            }
            trObj.icon = "harvest_"+ arr[i].PropId+"_png";
            trObj.msg = trObj.PackMsg;
            trObj.date = "下单时间："+trObj.OrderDate;
            trObj.node = "共"+ trObj.PackNum + "件商品"
            this._logisticsData.push(trObj);
        }
        this._arrayData = new eui.ArrayCollection(this._logisticsData);
        this.list.dataProvider = this._arrayData;
        this._arrayData.refresh();
     }
}
class logisticsIR extends eui.ItemRenderer{
    // private changeBtn:eui.Button;
    public constructor(){
        super();
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "logisticsIRSkin";
    }
    private createCompleteEvent():void{
        super.createChildren();
        this.removeEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent, this);
        // this.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
        //     this.selected = true;
        //     this.dataChanged();
        // },this);
    }
    protected dataChanged():void{
        // if(this.selected === true){
        //     this.changeBtn.enabled = false;
        // }else{
        //     this.changeBtn.enabled = true;
        // }
    }
}

